#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

%:
	dh $@ --buildsystem=makefile

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_installinit:
	mkdir -p debian/grr-client/usr/sbin
	mkdir -p debian/grr-client/usr/lib/grr
	mkdir -p debian/grr-client/usr/share/man/man1
	install -p -m755 debian/tmp/usr/lib/grr/*.* debian/grr-client/usr/lib/grr/
	install -p -m755 debian/tmp/usr/lib/grr/grrd debian/grr-client/usr/lib/grr/grrd
	install -p -m0644 grr/config/debian/manuals/*.1 debian/grr-client/usr/share/man/man1
	install -p -m755 grr/config/debian/upstart/grr-client.conf debian/grr-client.upstart
	# Create upstart scripts
	sed "s/#JOB#/grr-client/;s/#ERROR_HANDLER#/exit \$$?/" \
	/usr/share/debhelper/autoscripts/postinst-upstart >> debian/grr-client.postinst.debhelper
	sed "s/#JOB#/grr-client/;s/#ERROR_HANDLER#/exit \$$?/" \
	/usr/share/debhelper/autoscripts/prerm-upstart >> debian/grr-client.prerm.debhelper
	dh_installinit --upstart-only
	# Create init.d scripts
	# These are kept in case an init.d based deb package needs to be build
	# sed "s/#SCRIPT#/grr-client/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$$?/" \
	# /usr/share/debhelper/autoscripts/postinst-init >> debian/grr-client.postinst.debhelper
	# sed "s/#SCRIPT#/grr-client/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$$?/" \
	# /usr/share/debhelper/autoscripts/prerm-init >> debian/grr-client.prerm.debhelper
	# sed "s/#SCRIPT#/grr-client/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$$?/" \
	# /usr/share/debhelper/autoscripts/postrm-init >> debian/grr-client.postrm.debhelper

override_dh_link:
	dh_link "/$(shell cd debian/grr-client/ && find usr/ -name grrd)" "/usr/sbin/grrd"

override_dh_strip:
	# Necessary otherwise the PyInstaller build executables will not run

override_dh_makeshlibs:
	# Prevent useless call to ldconfig
	dh_makeshlibs -n

override_dh_shlibdeps:
	# Point debhelper to the locally included shared libraries
	dh_shlibdeps -l${PWD}/debian/tmp/usr/lib/grr

